package dao

import (
	"system-admin/internal/models"
	"system-admin/internal/utils"
)

// 获取前X个博客文章记录
func QueryBlogEssayInLimit(limitQuantity int) (blogList *models.BlogList, result bool, row int) {
	db := utils.GetDB()
	blogList = &models.BlogList{}

	queryResult := db.Table("blog_essays").Limit(limitQuantity).Find(&blogList.BlogEssay)

	row = int(queryResult.RowsAffected)
	if row != 0 {
		//成功查询
		result = true
	} else {
		//查询不到
		result = false
	}
	return
}

// 根据博客列表里的id查各自的用户信息
func QueryUserByBlog(blogUIDList [100]string) (userList *models.UserList, result bool, row int) {
	db := utils.GetDB()
	userList = &models.UserList{}

	queryResult := db.Where("uid IN ?", blogUIDList).Find(&userList.User)

	row = int(queryResult.RowsAffected)
	if row != 0 {
		//成功查询
		result = true
	} else {
		//查询不到
		result = false
	}
	return
}
